package com.example.main.rottweiljson;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class RottweilHttpRequest {

    public static void request(String url, OnRequestListner onRequestListner) {
        OkHttpClient okHttpClient = new OkHttpClient();
        final Request request = new Request.Builder()
                .url(url)
                .build();
        final Call call = okHttpClient.newCall(request);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Response response = call.execute();
                    if (onRequestListner != null) {
                        onRequestListner.onResult(response.body().string());
                    }
                    //System.out.println(response.body().string());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    public interface OnRequestListner {
        void onResult(String result);
    }
}
